package com.heu.blood.recycle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heu.blood.match.entity.BloodMatchEntity;
import com.heu.blood.match.service.BloodInformationService;
import com.heu.blood.match.service.BloodMatchService;
import com.heu.blood.recycle.dao.BloodTrackBoDao;
import com.heu.blood.recycle.entity.BloodTrackBo;
import com.heu.blood.recycle.service.BloodBagDestroyService;
import com.heu.blood.recycle.service.BloodBagRecycleService;
import com.heu.blood.recycle.service.BloodTrackBoService;
import com.heu.blood.recycle.service.BloodTrackService;
import com.heu.blood.storge.dao.BloodInStorgeDao;
import com.heu.blood.storge.dao.BloodOutStorgeDao;
import com.heu.blood.storge.entity.BloodInStorgeEntity;
import com.heu.blood.storge.entity.BloodOutStorgeEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BloodTrackBoServiceImpl extends ServiceImpl<BloodTrackBoDao, BloodTrackBo> implements BloodTrackBoService {


    @Autowired
    private BloodInformationService bloodInformationService;
    @Autowired
    private BloodTrackService bloodTrackService;
    @Autowired
    private BloodInStorgeDao bloodInStorgeDao;
    @Autowired
    private BloodOutStorgeDao bloodOutStorgeDao;
    @Autowired
    private BloodMatchService bloodMatchService;
    @Autowired
    private BloodBagRecycleService bloodBagRecycleService;
    @Autowired
    private BloodBagDestroyService bloodBagDestroyService;


    @Override
    public BloodTrackBo query(String bloodId) {

        //构造血液追踪信息返回对象
        BloodTrackBo bloodTrackBo = new BloodTrackBo();
        //血液信息写入
        bloodTrackBo.setBloodInformationEntity(bloodInformationService.queryByBloodId(bloodId));
        //发取血信息写入
        bloodTrackBo.setBloodTrackEntity(bloodTrackService.queryByBloodId(bloodId));
        //入库信息
        LambdaQueryWrapper<BloodInStorgeEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BloodInStorgeEntity::getBloodId,bloodId)
                    .eq(BloodInStorgeEntity::getIfShow,1);
        bloodTrackBo.setBloodInStorgeEntity(bloodInStorgeDao.selectOne(queryWrapper));
        //出库信息
        LambdaQueryWrapper<BloodOutStorgeEntity> queryWrapper1 = new LambdaQueryWrapper<>();
        queryWrapper1.eq(BloodOutStorgeEntity::getBloodId,bloodId)
                     .eq(BloodOutStorgeEntity::getIfShow,1);
        bloodTrackBo.setBloodOutStorgeEntity(bloodOutStorgeDao.selectOne(queryWrapper1));
        //配血信息写入
        LambdaQueryWrapper<BloodMatchEntity> queryWrapper2 = new LambdaQueryWrapper<>();
        queryWrapper2.eq(BloodMatchEntity::getBloodId,bloodId)
                        .eq(BloodMatchEntity::getIfShow,1);
        bloodTrackBo.setBloodMatchEntity(bloodMatchService.list(queryWrapper2));
        //血袋回收信息写入
        bloodTrackBo.setBloodBagRecycleEntity(bloodBagRecycleService.query(bloodId));
        //血袋销毁信息
        bloodTrackBo.setBloodBagDestroyEntity(bloodBagDestroyService.query(bloodId));

        return bloodTrackBo;
    }
}
